import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager


class Driver:
   driver = ""
   def __init__(self):
      options = webdriver.EdgeOptions()
      self.driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()),options=options)
      #隐式等待
      self.driver.implicitly_wait(3)
   def getScreeShot(self):
      #创建存放屏幕截图的文件夹以及字文件夹
      dirname = datetime.datetime.now().strftime("%Y-%m-%d")
      #判断images文件夹下是否创建dirname文件夹，不存在则创建
      if not os.path.exists("../images/"+dirname):
         os.mkdir("../images/"+dirname)

      #创建屏幕截图
      filename =sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") + ".png"
      self.driver.save_screenshot("../images/"+dirname+"/"+filename)

BlogDriver = Driver()

